package jn.chen;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;

/**
 * @className: Application
 * @author: chenLin
 * @version: 1.0.0
 * @description:
 * @date: 2022/11/1 0001 10:07
 */
@SpringBootApplication
public class Application {
    public static void main(String[] args)
    {
        SpringApplication.run(Application.class, args);
    }

    /**
     * SpringBoot 2.0.0 以上都采用内置tomcat8.0以上版本，
     * 而tomcat8.0以上版本遵从RFC规范添加了对Url的特殊字符的限制，
     * url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~四个特殊字符
     * 以及保留字符( ! * ’ ( ) ; : @ & = + $ , / ? # [ ] ) (262+10+4+18=84)
     * 这84个字符,请求中出现了{}大括号或者[],所以tomcat报错。设置RelaxedQueryChars允许此字符，
     * 设置requestTargetAllows选项(Tomcat 8.5中不推荐)。
     * @return
     */
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                connector.setProperty("relaxedQueryChars", "|{}[]\\");
            }
        });
        return factory;
    }

}
